<?php

class IndustryController extends BaseController{
    
    protected $table = 'industries';

    public function getList(){

        try{
            if($shop_id = Input::get('shop_id')){
               echo json_encode(Industries::Show($shop_id)); 
            }
        }
        catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
    }

    public function postRegister(){
        //input json array 
        try
        {
            $input=Input::json()->all();

            $shop_id=InputHelper::getInput($input,'shop_id',null);

            $description=InputHelper::getInput($input,'description',null);

            $name=InputHelper::getInput($input,'name',null);
        }
        catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
    	try{
            if($industry_id =Industries::Insert($name,$description,$shop_id))
            {
                
                    return Response::json(array('status'=>'success','id'=>$industry_id ));
               
            }
    	}
    	catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
    	}
    }
    public function postEdit(){
        try
        {
            $input=Input::json()->all();

            $industry_id=InputHelper::getInput($input,'industry_id',null);

            $description=InputHelper::getInput($input,'description',null);

            $name=InputHelper::getInput($input,'name',null);
        }catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }

        try{
            if(Industries::Edit($industry_id,$name,$description))
            {
                return Response::json(array('status'=>'success'));
            }
        }
        catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }

    }
    public function postDeletedata(){
        try{
             $input = Input::all();
             if (array_key_exists('industry_id', $input)) {
                $industry_id = $input('industry_id');
            }
            else{

                return ErrorResponse::SendErrorMessage('industry id invalid');
            }
            if(Industries::deletedata($industry_id)){
                return Response::json(array('status'=>'success'));
            }
        }
        catch(Exception $e){
            return ErrorResponse::SendErrorMessage($e->getMessage());
        }
    }
}
